import os

# 设置路径
path = r"E:\2025-03-20_17_10_52\a\yolo2"  # 替换为你的实际路径

# 遍历所有txt文件
for file in os.listdir(path):
    if file.endswith(".txt"):
        file_path = os.path.join(path, file)

        # 读取文件内容并处理
        with open(file_path, "r") as f:
            lines = f.readlines()

        new_lines = []
        for line in lines:
            parts = line.strip().split()
            if len(parts) > 0:
                parts[0] = str(int(parts[0]) - 1)  # 类别编号减1
                new_lines.append(" ".join(parts))

        # 覆盖写入新内容
        with open(file_path, "w") as f:
            f.write("\n".join(new_lines) + "\n")

        print(f"Processed: {file_path}")

print("所有标注文件处理完成！")
